<html>
  <head>
    <title>TIScript syntax</title>
    <link rel="stylesheet" href="for-screen.css"/>
    <meta name="generator" content="h-smile:richtext"/>
  </head>
<body>
  <h1>Statements</h1><input type="checkbox" checked id="show-defintions"/> show/hide definitions.
  <dl>
    <dt><strong><code>{</code></strong> &lt;statements&gt; <strong><code>}</code></strong></dt>
    <dd>A sequence of statements, delimited by the curly brackets, '{' and '}', is called a <strong>block</strong>. A block is itself a statement. Each block establishes its own namespace for the variables declared by the <strong>var</strong> and <strong>const</strong> statements.</dd>
    <dt><strong><code>if</code></strong> <strong><code>(</code></strong> &lt;expression&gt; <strong><code>)</code></strong> &lt;statement&gt; [ <strong><code>else</code></strong> &lt;statement&gt; ]</dt>
    <dd>Conditionally executes a statement, depending on the result of the &lt;expression&gt;.</dd>
    <dt><strong><code>while</code></strong> [ <code><strong>:</strong></code> name ] <strong><code>(</code></strong> &lt;expression&gt; <strong><code>)</code></strong> &lt;statement&gt;</dt>
    <dd>Executes &lt;statement&gt; while the &lt;expression&gt; evaluates to true. The <em>label</em> can be used in named <em>break</em>, and <em>continue</em> statements.</dd>
    <dt><strong><code>do</code></strong> [ <code><strong>:</strong></code> label ] &lt;statement&gt; <strong><code>while</code></strong> <strong><code>(</code></strong> &lt;expression&gt; <strong><code>)</code></strong></dt>
    <dd>Executes the &lt;statement&gt; once, and then repeats execution of the statement while the &lt;expression&gt; evaluates to <em>true</em>.</dd>
    <dt><strong><code>for</code></strong> [ <code><strong>:</strong></code> label ] <strong><code>(</code></strong> &lt;init-expression&gt; | <strong><code>var</code></strong> &lt;name-with-initialization&gt; <code>;</code> [&lt;condition-expression&gt;] <code>;</code> [&lt;inc-expression&gt;] <strong><code>)</code></strong> &lt;statement&gt;</dt>
    <dd>Executes the &lt;statement&gt; as long as the &lt;condition-expression&gt; evaluates to <em>true</em>.</dd>
    <dt><strong><code>for</code></strong> [ <strong><code>:</code></strong> label ] <code><strong>(</strong></code> [ <strong><code>var</code> </strong>] &lt;name&gt; <strong><code>in</code></strong> &lt;expression&gt; <code><strong>)</strong></code> &lt;statement&gt;</dt>
    <dd>Executes the &lt;statement&gt; for every element contained in an array, object, or a function (a.k.a. generator-function). If the &lt;expression&gt; is an array, the &lt;name&gt; variable receives consecutive members of the array on each iteration. For the object, it receives the name (a.k.a. key) of each property. If the &lt;expression&gt; is a function, the for-in will invoke the function on each itearation until the function returns nothing. This happens if the function reaches the end of its body without a return statement (but it returns the <em>nothing</em> value in this case).</dd>
    <dt><strong><code>for</code></strong> [ <strong><code>:</code></strong> label ] <code><strong>(</strong></code> [ <strong><code>var</code> </strong>] <em>&lt;name-list&gt;</em> <strong><code>in</code></strong> &lt;expression&gt; <code><strong>)</strong></code> &lt;statement&gt;</dt>
    <dd>Where the <em>&lt;name-list&gt;</em> is list of variables separated by the comma <code><strong>,</strong></code> and enclosed by <code><strong>(</strong></code> <code><strong>)</strong></code> parentheses.<br/>This form of the for-in executes the &lt;statement&gt; for every element contained in an array, object, or a function (a.k.a. generator-function). <br/>If the &lt;expression&gt; is an array, the variables in the <em>name-list</em> receive consecutive index value <strong>and</strong> value of the correspondent array member on each iteration. For the object, first variable receives the name (a.k.a. key) of the property and second variable will receive the value of the property. If the &lt;expression&gt; is a function, the for-in will invoke the function on each itearation until the function returns nothing. Variables in the <em>&lt;name-list&gt;</em> will receive returned value of values if the function returns list of values.<br/>Examples:<br/><code>for( var (k,v) in obj ) stdout.printf(&quot;k=%s,v=%v,&quot;, k, v);</code> &nbsp;- prints names and values of each property of the object.<br/><code>for( var (i,v) in arr ) stdout.printf(&quot;i=%d,v=%v,&quot;, i, v);</code> &nbsp;- prints indexes and values of each member of the array.</dd>
    <dt><strong><code>switch</code> <code>(</code> </strong>&lt;selector-expression&gt; <strong><code>)</code> <code>{</code> <code>case</code> </strong>&lt;case-expression&gt;<strong> <code>:</code> </strong>&lt;statements&gt; [...] <strong><code>default:</code> </strong>&lt;statement&gt; <strong><code>}</code></strong></dt>
    <dd>The <strong>switch</strong> statement allows to select one of the many blocks of code for execution. When the result of &lt;case-expression&gt; equals the value of the &lt;selector-expression&gt;, the corresponding &lt;statements&gt; are executed. If there is no matching &lt;case-expression&gt;, the statements marked by the <code>default:</code> label get executed (if present).</dd>
    <dt><strong><code>break</code></strong> [label]<strong> <code>;</code></strong></dt>
    <dd>The <strong>break</strong> statement terminates the execution of loops (for, for in, while or do/while) and switch statements. If the label is provided, it's a so-called named break statement. It breaks the outer loop, marked by the corresponding label. It is a syntax error if no such label is found in the current scope.<br/>Example: <br/><code>for:outer ( var row in rows )<br/>for:x ( var cell in row )<br/> &nbsp;&nbsp;if ( cell == current ) break outer;</code></dd>
    <dt><strong><code>continue</code></strong> [label]<strong> <code>;</code></strong></dt>
    <dd>The <strong>continue</strong> statement forces a loop (for, for in, while or do/while) to skip to the next iteration. If the label is provided, it's a so called named continue statement. It will iterates the outer loop, marked by the corresponding label. It is a syntax error if no such label is found in the current scope.</dd>
    <dt><strong><code>var</code></strong> &lt;name-or-name-list&gt; [ <strong><code>=</code></strong> &lt;init-expression&gt;] [ <strong><code>,</code></strong> &lt;name&gt; [<strong>=</strong> &lt;init-expression&gt;] ... ] <strong><code>;</code></strong></dt>
    <dd>The <strong>var</strong> statement introduces a new variable local to the current scope. Blocks ( <code><strong>{</strong></code> ... <code><strong>}</strong></code> ) establish variable scopes in the language. (<em>Note</em>: In JavaScript, the scope is established only by the body of a function).<br/><em>&lt;name-or-name-list&gt;</em> here is either single <em>&lt;name&gt;</em> or group of names enclosed by <code><strong>(</strong></code> and &nbsp;<code><strong>)</strong></code> parentheses and separated by the comma <code><strong>,</strong></code> <br/>Example:<br/><code>var (a,b,c) = 1;</code> - declares variables a,b,c and assigns value '1' to them.<br/><code>var (a,b,c) = (1,2,3);</code> - equivalent of <code>var a = 1, b = 2, c = 3;</code></dd>
    <dt><strong><code>return</code></strong> [ &lt;expression&gt; | &lt;expression-list&gt; ] <strong><code>;</code></strong></dt>
    <dd>The <strong>return</strong> statement terminates the execution of the current function, optionally returning the result of the &lt;expression&gt; or &lt;expression-list&gt;. If the expression is omitted, the function will return the special <em>undefined</em> value. <br/>Note that the <em>return</em> can return multiple values by providing expressions list:<br/><code>function rect() { return (10,10,100,100); }<br/>var (x,y,width,height) = rect(); // x and y get '10' and width and height get '100' values.</code></dd>
    <dt><strong><code>const</code></strong> &lt;name&gt; <strong>=</strong> &lt;init-expression&gt; [ <strong><code>,</code></strong> &lt;name&gt; <strong>=</strong> &lt;init-expression&gt; ... ] <strong><code>;</code></strong></dt>
    <dd>The <strong>const</strong> statement introduces a new named constant, local to the current scope. Autside the const statement, any attempt to assign another value to the &lt;name&gt; will generate a compile-time error.</dd>
    <dt><strong><code>try</code></strong> &lt;statement&gt; <strong><code>catch</code></strong> <strong><code>(</code></strong> &lt;variable-name&gt; <strong><code>)</code></strong> &lt;catch-statement&gt; <strong><code>finally</code></strong> &lt;finally-statement&gt;</dt>
    <dd>The <strong>try</strong> statement encloses a block of code in which an exceptional condition may occur, such as a runtime error, or a <strong>throw</strong> statement. The catch clause provides the exception handling code. When a catch clause catches an exception, its &lt;variable-name&gt; is bound to that exception. The &lt;finally-statement&gt; is executed unconditionally after the <strong>try</strong> block - both in the case of an exception, and if the &lt;statement&gt; executes normally.</dd>
    <dt><strong><code>assert</code></strong> &lt;test-expression&gt; [ <strong><code>:</code></strong> &lt;info-expression&gt; ] <strong><code>;</code></strong></dt>
    <dd>The <strong>assert</strong> statement allows you to test assumptions about your program. When the &lt;test-expression&gt; evalutes to <em>false</em> at runtime, an error is thrown with the source text of the &lt;test-expression&gt; and &lt;info-expression&gt; (if any).</dd>
    <dt>&lt;expression&gt;<strong> <code>;</code></strong></dt>
    <dd>Expressions that end with ';' constitute a single statement. Result of the &lt;expression&gt; is suppressed.</dd></dl>
</body>
</html>